package cc.ufinity.networkdiagnose.view;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import cc.ufinity.networkdiagnose.widget.SettingWidget;

public class CfgActivity extends AbstractActivity{
	private SettingWidget textView ;
	private Handler mHandler;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHandler = new Handler() {

			@Override
			public void handleMessage(Message msg) {
				switch(msg.what) {
				case 1:
					dismissExitDialog();
					exit();
					break;
				}
			}
			 
		 };
       textView = new SettingWidget(this);
		setContentView(textView);
		
		//setContentView(new CameraWidget(this));
    }

/*	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (KeyEvent.KEYCODE_BACK == keyCode) {
			Log.d("布局", getCurrentFocus().toString());
			Log.d("返回 系统管理", "返回按钮");
			SettingWidget textView = new SettingWidget(this);
			setContentView(textView);
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}*/
    //修改
public boolean onKeyDown(int keyCode, KeyEvent event) {
		
		if(keyCode==KeyEvent.KEYCODE_BACK){
			setContentView(textView);	
			return true;
		}else if(keyCode==KeyEvent.KEYCODE_MENU){
				AlertDialog.Builder builder = new AlertDialog.Builder(this);
				builder.setTitle("提示");
//				builder.setIcon(R.drawable.what);
				builder.setMessage("确定退出系统吗？");
				builder.setCancelable(false);
				builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						webLogout(mHandler);
						dialog.dismiss();
						showExitDialog();
					}
				});
				builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						dialog.cancel();
					}
				});
				builder.show();
			}
		return false;
	}
}
